package org.dolphin.entity.security;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.dolphin.base.constant.DatabaseAttribute;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.util.ObjectUtils;

@Entity
@Table(name = "XS_ACCESS_CONTROL", uniqueConstraints = {@UniqueConstraint(columnNames = {"AUTHORITY"}, name = "UQ_XS_ACCESS_CONTROL_AUTHORITY")})
public class AccessControl implements Serializable {
  private static final long serialVersionUID = -4603470299974067851L;
  private String id;
  private String authority;
  private String description;

  @Override
  public boolean equals(Object obj) {
    if (obj == this) {
      return true;
    } else if (obj instanceof AccessControl) {
      AccessControl oth = (AccessControl) obj;
      return ObjectUtils.nullSafeEquals(getId(), oth.getId());
    }
    return false;
  }

  @Column(name = "AUTHORITY", length = 100, nullable = false)
  public String getAuthority() {
    return authority;
  }

  @Column(name = "DESCRIPTION", length = 200, nullable = false)
  public String getDescription() {
    return description;
  }

  @Id
  @GeneratedValue(generator = "uuid2")
  @GenericGenerator(name = "uuid2", strategy = "org.dolphin.base.id.generator.CustomUUIDGenerator")
  @Column(name = "ID", nullable = false, length = DatabaseAttribute.ID_LENGTH)
  public String getId() {
    return id;
  }

  @Override
  public int hashCode() {
    int hash = ObjectUtils.nullSafeHashCode(getId());
    return hash;
  }

  public void setAuthority(String authority) {
    this.authority = authority;
  }

  public void setDescription(String description) {
    this.description = description;
  }

  public void setId(String id) {
    this.id = id;
  }
}
